export const base64_chars =
  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

/**
 * @param {string} char - only base64 char
 * @returns {number}
 */
export function char2index(char) {
  if (char === "/") return 63;
  if (char === "+") return 62;
  const charCode = char.charCodeAt(0);
  if (charCode >= 48 /* 0 */ && charCode <= 57 /* 9 */) return charCode + 4; // charCode - 48 + 52;
  if (charCode >= 65 /* A */ && charCode <= 90 /* Z */) return charCode - 65; // charCode - 65 + 0;
  if (charCode >= 97 /* a */ && charCode <= 122 /* z */) return charCode - 71; // charCode - 97 + 26;
  throw new Error("char must be base64 char");
}

/**
 * @param {number} index - 0 <= index <= 63
 * @returns {string}
 */
export function index2char(index) {
  return base64_chars[index];
}
